<?php
	require_once("include/header.php");
	#include 'include/functions.php';
	
	if ($userID != 1)
	{
		?>
			<SCRIPT language="JavaScript">
				<!--
					window.location="logoff.php";
				//-->
			</SCRIPT>
		<? 
	}
	echo "Hello?";
	
	//Connect To Database
	dbConnect();

	$SQL = "DELETE FROM NHLPicks WHERE UserID = 7";
	$result = mysql_query($SQL) or die("Cannot query the database.<br/>");

	$Num_of_Picks = 0;
	//Loop Through Every Week Of The Season
	for($i = 1; $i < 18; $i++)
	{
		/*Create a Record in "NHLPicks" for this week.
		RandomMonkey's UserID is 7  */
		$SQL = "INSERT INTO NHLPicks (UserID, Week) VALUES (7, $i)";
		$result = mysql_query($SQL) or die("Cannot query the database.<br/>");


		//Grab All The Games For The Current Week.
		$SQL = "SELECT Week, GameNum, Home, Away FROM NHLSchedule WHERE Week = $i";
		$result = mysql_query($SQL) or die("Cannot query the database.<br/>");

		/*For Each Game In the current week, get a random number, and insert random pick 
		into NHLPicks for that Game.*/
		do
		{
		   if($myrow["Away"] != "")
		   {
			//Get Random Seed
			srand(make_seed());
			//Generate Random 1 or 0
			$random = (rand()%2);
			//Start SQL update Statement
			$GameNum = "Game";
			$GameNum .= $myrow["GameNum"];
			echo "$random<br />";
			$SQL = "UPDATE NHLPicks SET ".$GameNum." = '";
	
			if($random == 0)
			{
				$SQL .= $myrow["Away"];
			}
			else
			{
				$SQL .= $myrow["Home"];
			}

			//Finish SQL UPDATE Statment
			$SQL .= "' WHERE ((Week = $i) AND (UserID = 7))";
			$newresult = mysql_query($SQL) or die("Cannot query the database.<br/>");
			echo $SQL."<br>";
			$Num_of_Picks++;
		   }//end IF
		} while($myrow = mysql_fetch_array($result));
	}

	//Update the number of picks made
	mysql_query("UPDATE NHLUsers SET PicksMade = $Num_of_Picks WHERE ID = 7") or die("Cannot query the database.<br/>");
